package com.zbkj.service.util;

import org.springframework.oxm.jaxb.Jaxb2Marshaller;

import javax.xml.transform.stream.StreamSource;
import java.io.StringReader;

/**
 * @author JXY
 * @date 2024/03/19
 */
public class XmlUtil {

    public static <T> T xmlToBean(String data, Class<T> clazz) {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setClassesToBeBound(clazz);
        return (T) marshaller.unmarshal(new StreamSource(new StringReader(data)));
    }

}
